/*
 * Alloy Analyzer
 * Copyright (c) 2002 Massachusetts Institute of Technology
 *
 * The Alloy Analyzer is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * The Alloy Analyzer is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with the Alloy Analyzer; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package alloy.sharbool;

import java.util.ArrayList;
import java.util.List;

import alloy.ast.Expr;
import alloy.ast.Node;
import alloy.util.ObjID;

/** The template instance information computed for each {@link Node} of the AST.
    For each distinct node of the AST, {@link TemplateDetectVisitor} computes a separate {@link TemplateInstance}
    object. */
class TemplateInstance extends ObjID {
    /** The node for which this information is computed */
    final Node node;

    /** The template of which {@link #node} is an instance with arguments {@link #args}. */
    Template template;
    
    /** Template arguments: this node is an instance of {@link #template}
	with the given arguments.  E.g., we might say that (a & P) (where a is
	a quantified variable and P a relation) is an instance of a template
	with argument list (a), while ((b+c) & P) is an instance of the same template
	with the argument list (b+c).  {@link List} of {@link Expr}s. */
    final List /* of Expr */ args = new ArrayList();
    
    TemplateInstance(Node node_) { this.node = node_; }

    public String toString() { return System.identityHashCode(template) + " " + args; }
    
    void setArgs(final List newArgList) {
		args.clear();
		for (int i = 0; i < newArgList.size(); i++) {
			args.add(newArgList.get(i));
		}
    }
}
